import { DateFormate } from "../js/date_tools.js";
//动态设置表格高度//
function autoheight(item,type) {
    const self = item;
    self.autoheight = window.innerHeight - type;
}
//动态生成进度跟踪页面的时间列
function getIntervalMonth(startDate, endStart){
    let monthArry = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    let intervalArry = [];
    let intervalMonth = '';
    let startDateYear = startDate.split("-")[0];
    let startDateMonth = startDate.split("-")[1];
    let endStartYear = endStart.split("-")[0];
    let endStartMonth = endStart.split("-")[1];
    if (startDateYear == endStartYear) {
        intervalMonth = Number(endStartMonth) - Number(startDateMonth);
    } else if (startDateYear < endStartYear) {
        intervalMonth = Number(endStartMonth) + (12 - Number(startDateMonth));
    } else if (startDateYear > endStartYear) {
        return
    }
    if (intervalMonth <= 12) {
        for (let index = 0; index <= intervalMonth; index++) {
            if (parseInt(startDateMonth) <= 12) {
                startDateMonth = parseInt(startDateMonth);
            } else {
                startDateMonth = 1;
                startDateYear = parseInt(startDateYear) + 1
            }
            let item = {
                title: startDateYear + '.' + monthArry[startDateMonth - 1],
                key: startDateYear + monthArry[startDateMonth - 1]
            }
            intervalArry.push(item)
            startDateMonth = startDateMonth + 1
        }
    }
    intervalArry.unshift({title:' ', key: "organName"})
    return intervalArry
}
//获取截止时间，一般为当前时间 format为日期格式，年月，年月日两种
function getEndtime(format){
    let dateStr = ''
    let nowDate = new Date();
    let year = nowDate.getFullYear();
    let month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
    let day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
    if (format == 'ym') {
        dateStr = year + "-" + month
    } else if (format == 'ymd') {
        dateStr = year + "-" + month + "-" + day;
    } else {
        dateStr = year + "-" + month + "-" + day;
    }
    return dateStr
}
//获取开始时间，自由获取 format为日期格式，年月，年月日两种,ahead 提前量,最小单位一个月
function getStartTime(format, ahead) {
    let dateStr = ''
    let nowDate = new Date();
    nowDate.setMonth(nowDate.getMonth() - ahead);
    let year = nowDate.getFullYear();
    let month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
    let day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
    if (format == 'ym') {
        dateStr = year + "-" + month
    } else if (format == 'ymd') {
        dateStr = year + "-" + month + "-" + day;
    } else {
        dateStr = year + "-" + month + "-" + day;
    }
    return dateStr
}
function objTotext(obj) {
    let sendDataMap = obj;
    let res = '';
    for (const key in sendDataMap) {
        if (sendDataMap.hasOwnProperty(key)) {
            const element = sendDataMap[key];
            let arr = element.split("#$#");
            res += arr[0] + ':' + arr[1] + '  ;  ' +' \n '
        }
    }
    return res
}
export { autoheight, getIntervalMonth, getEndtime, getStartTime, objTotext}